PS = c
CC = gcc
CFLAGS = -std=gnu99 -g3 -D_BSD_SOURCE -O0 -DNEW_IP_MATCH -DMI_RST_V2 -DJ_CAPMODE_ZCP -DRZGL_LOG -DXJ_KEYWORD -DXJ_WANGGUAN -DMI_DNSCHEAT_ON -DMI_DNSIPRST_ON -DXJ_DNSCHEAT_ON
#-fdump-rtl-expand
#CFLAGS = -std=gnu99 -g3 -Wall -D_BSD_SOURCE -O0 -DRZGL_LOG -DPCAP_REPLAY
DEST := xj_gkjc
LIBS := net pthread dl pcap m avro xml2 
INCLUDES := ./kernel ./base ./algorithm ./misc ./json  ./kernel/rzgl /include ./dns_cheat 
SUB_DIR := kernel base algorithm misc json kernel/rzgl
DEST_DIR := ./
INSTALL := /usr/local/bin

RM := rm -f
CFLAGS += -MMD -MF $(patsubst ./%, %, $(patsubst %.o, %.d, $(dir $@).$(notdir $@))) $(addprefix -I, $(INCLUDES))
SRCS := $(wildcard *.$(PS) $(addsuffix /*.$(PS), $(SUB_DIR)))
OBJS := $(patsubst %.$(PS), %.o, $(SRCS))
DEPS := $(patsubst %.$(PS), %.d, $(foreach n, $(SRCS), $(patsubst ./%, %, $(dir $n).$(notdir $n))))
MISS := $(filter-out $(wildcard DEPS), $(DEPS))

all : $(DEST)
	
install :
	cp -f $(DEST) $(DEST_DIR)/$(DEST)

ifneq ($(MISS),)
	$(MISS):
	@$(RM) $(patsubst %.d, %.o, $(dir $@)$(patsubst .%,%, $(notdir $@)))
endif

clean :
	@$(RM)	$(DEST)	$(DEST_DIR)/$(DEST) $(OBJS) $(DEPS)

-include $(DEPS)

$(DEST) : $(OBJS)
	$(CC) -o $(DEST) $(OBJS) $(addprefix -l, $(LIBS))
  
